<?php

namespace app\admin\middleware;

use think\facade\Session;

class CategoryAdmin
{
    public function handle($request, \Closure $next)
    {
        $role = Session::get('admin.role');
        if (Session::has('admin') && $role != 0) {
            $controller = strtolower(request()->controller());
            $action = strtolower(request()->action());
            $permitPath = [
                'index' => ['index'],
                'article' => [
                    'index',
                    'edit',
                    'doEdit',
                    'list',
                    'del',
                    'add',
                    'doAdd',
                    'examineAll',
                    'uploadImg',
                    'read'
                ],
                'system' => [
                    'password',
                    'changePwd'
                ]
            ];
            if (!in_array($controller, $permitPath) && !in_array($action, $permitPath[$controller])) {
                return view('error/error', ['msg' => "权限不足"]);
            }
        }
        return $next($request);
    }
}
